// https://api.qingnian8.com/
// https://gitee.com/qingnian8/univue3

const BASE_URL = 'https://tea.qingnian8.com/api/bizhi/';

export function request( config={} ){
	
	let { url, method="GET", header={}, data={} } = config;
	
	url = BASE_URL + url;
	header['access-key'] = "vincentzyu";
	// header['token'] = '1145141919810';
	
	return new Promise((resolve, reject)=>{
		uni.request({
			url: url,
			data: data,
			method: method,
			header: header,
			
			success: res=>{
				if ( res.data.errCode===0 ){
					// resolve(res);
					resolve(res.data); //向内走一层，不是所有的都需要
				} else if ( res.data.errCode===400){
					uni.showModal({
						title: "i am title:",
						content: "i am content: " + res.data.errMsg,
						showCancel: false
					});
					reject(res.data);
				} else {
					uni.showToast({
						title: "i am title: " + res.data.errMsg,
						icon: "none"
					})
					reject(res.data);
				}
			},
			fail: err=>{
				reject(err)
			}
		})
	})
	
}